<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <p>
      <span>昵称：</span><input id="username" placeholder="小明" />
      <span id="sp1">请输入中文</span>
    </p>
    <script>
      var reg = /[\u4e00-\u9fa5].$/g;
      username.onblur = function () {
        console.log(reg.test(username.value));
        if (reg.test(username.value)) {
          //value的值找不到
          sp1.innerText = "格式正确";
        } else {
          username.value = username.value.replace(username.value, "");
        }
      };
    </script>
  </body>
</html>
